import { GetServerSideProps } from "next"
import { Book } from "../../../types"
import PageLayout from "../../../segments/PageLayout"
import BookTocBlock from "../../../segments/BookTocBlock"

import { getBookByPath } from "../../../server/app/BookService"

const BookPostPage: React.FC<{ path: string; book: Book }> = ({ path, book }) => {
  return (
    <PageLayout>
      <div className="post-layout">
        <div className="left">{path}</div>
        <div className="post">
          <BookTocBlock book={book} title={book.title} titleUrl={`/b/${book.path}`} />
        </div>
        <div className="right">TODO:</div>
      </div>
    </PageLayout>
  )
}

export default BookPostPage

export const getServerSideProps: GetServerSideProps = async (ctx) => {
  const bookPath = ctx.params?.bookPath!

  return {
    props: {
      path: bookPath,
      book: await getBookByPath(bookPath as string),
    },
  }
}
